package cn.lovezaoan.hpcenter.manager
{
    import flash.events.Event;
    import mx.collections.ArrayList;
    import cn.lovezaoan.hpcenter.manager.PortalManager;
    import org.flexunit.asserts.*;
    import org.flexunit.async.Async;
    
    public class PortalManagerTest
    {
        
        [BeforeClass]
        public static function setUpBeforeClass():void
        {
        }
        
        [AfterClass]
        public static function tearDownAfterClass():void
        {
        }
        
        private var mgr:PortalManager;
        
        [Ignore("not to run")]
        [Test(async)]
        public function blogTest():void
        {
            var mgr:PortalManager = new PortalManager(201, "blog", this, "200");
            mgr.requestMessagesByTypeAndAsyncResponse();
            mgr.htmlExtract.html.addEventListener(Event.COMPLETE, Async.asyncHandler(this, handleHtmlLoaded, 60000, null, handleEventNeverOccurred), false, 0, true);
        }
        
        [Ignore("not to run")]
        [Test(async)]
        public function flashTest():void
        {
            var mgr:PortalManager = new PortalManager(103, "flash", this, "100");
            mgr.requestMessagesByTypeAndAsyncResponse();
            mgr.htmlExtract.html.addEventListener(Event.COMPLETE, Async.asyncHandler(this, handleHtmlLoaded, 60000, null, handleEventNeverOccurred), false, 0, true);
        }
        
        public function handleMessages(msgs:ArrayList, portalType:int):void
        {
            assertNotNull(msgs);
            trace(msgs.length);
        }
        
        [Test(async)]
        public function newsTest():void
        {
            var mgr:PortalManager = new PortalManager(102, "list", this, "100");
            commonHandle(mgr);
        }
        
        [Ignore("not to run")]
        [Test(async)]
        public function requestMessagesByTypeAndAsyncResponse():void
        {
            mgr.requestMessagesByTypeAndAsyncResponse();
            mgr.htmlExtract.html.addEventListener(Event.COMPLETE, Async.asyncHandler(this, handleHtmlLoaded, 60000, null, handleEventNeverOccurred), false, 0, true);
        }
        
        [Before]
        public function setUp():void
        {
            this.mgr = new PortalManager(105, "list", this, "100");
        }
        
        [After]
        public function tearDown():void
        {
        }
        
        protected function handleEventNeverOccurred(passThroughData:Object):void
        {
            fail("Timeout readed before event");
        }
        
        protected function handleHtmlLoaded(event:Event, passThroughData:Object):void
        {
            trace("--PortalManager--requestMessagesByTypeAndAsyncResponse--successful!!");
        }
        
        private function commonHandle(mgr:PortalManager):void
        {
            mgr.requestMessagesByTypeAndAsyncResponse();
            mgr.htmlExtract.html.addEventListener(Event.COMPLETE, Async.asyncHandler(this, handleHtmlLoaded, 60000, null, handleEventNeverOccurred), false, 0, true);
        }
    }
}